package Model.Beans.Results;

import Model.XML.*;
import java.util.*;
import Model.Beans.*;

public class Course_Student implements XMLRequestInterface {
    
    private Course course;
    private ArrayList students = new ArrayList(); 
    private XMLWriter xml = new XMLWriter();
    
    public Course_Student() {}    
    
    public void setCourse(Course course)
    {
        this.course = course;
    }
    
    public Course getCourse()
    {
        return course;
    }
    
    public void addStudent(Person student)
    {
        students.add(student);
    }
    
    public void addStudent(Person student, int index)
    {
        students.add(index, student);
    }
    
    public void delStudent(Person student)
    {
        students.remove(student);
    }
    
    public void delStudent(int index)
    {
        students.remove(index);
    }
    
    public ArrayList getStudents()
    {
        return students;
    }
    
    public String toXML() 
    {
        //<course-student>
        xml.Push("course_student");
       
        String[] attributeName = new String[5];
        String[] attribute = new String[5];
        attributeName[0] = "professor-name";
        attributeName[1] = "time";
        attributeName[2] = "days";
        attributeName[3] = "id";
        attributeName[4] = "classroom";
            
        attribute[0] = course.getProfessor().toString();
        attribute[1] = course.getTime();
        attribute[2] = course.getDays();
        attribute[3] = Integer.toString(course.getId());
        attribute[4] = course.getClassRoom().toString();
        
        xml.Element("course", course.getTitle(), attributeName, attribute);
      
        if(students.size() > 0)
            for(int i=0; i<students.size(); i++)
            {
                Person s = (Person)students.get(i);
                xml.Element("student", s.toString(), Integer.toString(s.getId()));
            }
        else
            xml.Element("student", "no-result");
        
        //</course-student>
        xml.Pop();
        return xml.GetXML();
    }
}
